// Copyright (c) 2025, 大连理工大学 (Dalian University of Technology)
//
// Licensed under the Mulan PSL v2.
// You can use this file according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of the License at
//
//     http://license.coscl.org.cn/MulanPSL2
//
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
// EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. SEE THE MULAN PSL v2
// FOR MORE DETAILS.

/*
 * @Author: yuanchenxi 836909158@qq.com
 * @Date: 2024-10-09 14:27:52
 * @LastEditors: qiulin 1746365080@qq.com
 * @LastEditTime: 2024-12-07 22:11:57
 * @FilePath: \SGFEM\Import\NastranBDF\src\Element\CONM2Parser.cpp
 */

#include "Import/BDFImport/BulkData/Element/CONM2Parser.h"

#include <iostream>

#include "boost/algorithm/string.hpp"

#include "Utility/Logging/SGLogger.h"

#include "DataStructure/Input/Element/CONM2Data.h"

#include "DBManager/DBServiceFactory.h"
#include "DBManager/IService/Input/Element/IElementService.h"

#include "Import/BDFImport/BDFImport.h"
#include "Import/BDFImport/BDFParserBase.h"
using namespace SG::DBManager;
using namespace SG::Import;
using namespace SG::DataStructure;
BULKDATA_ENTRY_PARSER_REG (CONM2);
/*
// file://./../../Doc/MarkDown/BulkData/CONM2/CONM2.md>
*/
// 以下需要修改
enum CONM2key
{
    CONM2KEY_EID    = 2,
    CONM2KEY_NODEID = 3,
    CONM2KEY_CID    = 4,
    CONM2KEY_MASS   = 5,
    CONM2KEY_X1     = 6,
    CONM2KEY_X2     = 7,
    CONM2KEY_X3     = 8,
    CONM2KEY_I11    = 12,
    CONM2KEY_I21    = 13,
    CONM2KEY_I22    = 14,
    CONM2KEY_I31    = 15,
    CONM2KEY_I32    = 16,
    CONM2KEY_I33    = 17,
};
SG::DataStructure::Common::Status BDF::BULKDATA::ParseCONM2 (const std::shared_ptr<SG::DBManager::DBServiceFactory>& dbServiceFactory,
                                                             std::vector<std::string>&                               dividedEntryInfo)

{
    SG::DataStructure::FEM::CONM2Data tempCONM2;
    // 解析字符串

    int curIDKey = 1;  // 当前字符串是第几项

    for (auto curStrKey : dividedEntryInfo)
    {
        if (is_all_space (curStrKey))
        {
            // 如果是空字符串，跳过
            curIDKey++;
            continue;
        }

        switch (curIDKey)
        {
        case CONM2KEY_EID:
            tempCONM2.m_id = convertToI64 (curStrKey);
            break;
        case CONM2KEY_NODEID:
            tempCONM2.m_g[0] = convertToI64 (curStrKey);
            break;
        case CONM2KEY_CID:
            tempCONM2.m_cId = convertToI64 (curStrKey);
            break;
        case CONM2KEY_MASS:
            tempCONM2.m_mass = convertToReal (curStrKey);
            break;
        case CONM2KEY_X1:
            tempCONM2.m_x[0] = convertToReal (curStrKey);
            break;
        case CONM2KEY_X2:
            tempCONM2.m_x[1] = convertToReal (curStrKey);
            break;
        case CONM2KEY_X3:
            tempCONM2.m_x[2] = convertToReal (curStrKey);
            break;
        case CONM2KEY_I11:
            tempCONM2.m_I1[0] = convertToReal (curStrKey);
            break;
        case CONM2KEY_I21:
            tempCONM2.m_I2[0] = convertToReal (curStrKey);
            break;
        case CONM2KEY_I22:
            tempCONM2.m_I2[1] = convertToReal (curStrKey);
            break;
        case CONM2KEY_I31:
            tempCONM2.m_I3[0] = convertToReal (curStrKey);
            break;
        case CONM2KEY_I32:
            tempCONM2.m_I3[1] = convertToReal (curStrKey);
            break;
        case CONM2KEY_I33:
            tempCONM2.m_I3[2] = convertToReal (curStrKey);
            break;
        }
        curIDKey++;
    }

    return dbServiceFactory->get<IElementService> ()->Add (tempCONM2);
}
